package com.lzdongrui.client.controller;

import com.lzdongrui.backend.domain.dto.ApplyLeaveDTO;
import com.lzdongrui.backend.domain.vo.ApplyLeaveVO;
import com.lzdongrui.backend.service.IApplyLeaveService;
import com.lzdongrui.common.annotation.Log;
import com.lzdongrui.common.core.controller.BaseController;
import com.lzdongrui.common.core.domain.AjaxResult;
import com.lzdongrui.common.core.page.TableDataInfo;
import com.lzdongrui.common.enums.BusinessType;
import com.lzdongrui.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/client/applyLeave")
public class ClientApplyLeaveController extends BaseController {

    @Autowired
    private IApplyLeaveService applyLeaveService;

    /**
     * 学生请假申请记录
     */
    @RequestMapping("/stuApplyLeavelist")
    public TableDataInfo stuApplyLeavelist(ApplyLeaveDTO applyLeaveDTO) {
        startPage();
        applyLeaveDTO.setStu(SecurityUtils.getClientUserId());
        return getDataTable(applyLeaveService.selClientStuApplyLeave(applyLeaveDTO));
    }

    /**
     * 学生请假申请
     */
    @PostMapping("/addStuApplyLeave")
    public AjaxResult add(@RequestBody ApplyLeaveDTO applyLeave)
    {
        applyLeave.setStu(SecurityUtils.getClientUserId());
        return toAjax(applyLeaveService.insertApplyLeave(applyLeave));
    }

    /**
     * 判断学生请假时间是否有效
     */
    @GetMapping("/checkStuLeaveTime")
    public AjaxResult isBetweenDate(ApplyLeaveDTO applyLeave) {
        applyLeave.setStu(SecurityUtils.getClientUserId());
        return AjaxResult.success(applyLeaveService.checkStuLeaveTime(applyLeave));
    }

    /**
     * 获取学生需要延长的假期
     */
    @GetMapping("/getExtendLeave")
    public AjaxResult getExtendLeave(ApplyLeaveDTO applyLeave){
        applyLeave.setStu(SecurityUtils.getClientUserId());
        return AjaxResult.success(applyLeaveService.getExtendLeave(applyLeave));
    }

    /**
     * 学生最后一条请假记录
     */
    @RequestMapping("/stuApplyLeaveLast")
    public TableDataInfo selClientStuApplyLeaveLast() {
        return getDataTable(applyLeaveService.selClientStuApplyLeaveLast(SecurityUtils.getClientUserId()));
    }

    /**
     * 获取待教师审核的请假记录
     */
    @RequestMapping("/getTeaApplyLeaveList")
    public TableDataInfo getTeaApplyLeaveList(ApplyLeaveDTO applyLeaveDTO){
        startPage();
        applyLeaveDTO.setUserid(getUserId());
        applyLeaveDTO.setUserDepId(getDeptId());
        applyLeaveDTO.setStatus(1);
        return getDataTable(applyLeaveService.selectApplyLeaveList(applyLeaveDTO));
    }

    /**
     * 学生取消申请
     */
    @DeleteMapping("/delApplyLeave/{id}")
    public AjaxResult delApplyLeave(@PathVariable("id") Long id){
        return success(applyLeaveService.deleteApplyLeaveById(id));
    }
}


